package com.szy.douyou_classification.web;

import com.szy.douyou_classification.config.ResultDTO;
import com.szy.douyou_classification.dao.Classification;
import com.szy.douyou_classification.dao.ClassificationReq;
import com.szy.douyou_classification.service.ClassificationService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author sunziyan
 * @date 2022/4/21
 */
@RestController
@RequestMapping("/classification")

public class ClassificationController {

    @Resource
    private ClassificationService classificationService;

    /**
     * 查询所有板块分类信息
     *
     * @return
     */
    @PostMapping("/queryAll")
    public ResultDTO queryAll(@RequestBody ClassificationReq classificationReq) {
        return classificationService.queryAllClassification(classificationReq);
    }

    /**
     * 根据主键id查询板块分类信息
     *
     * @param classificationId
     * @return
     */
    @GetMapping("/queryOne/{classificationId}")
    public ResultDTO<Classification> queryOne(@PathVariable("classificationId") Long classificationId) {

        return classificationService.queryOneClassification(classificationId);
    }


    /**
     * 新增分类
     *
     * @param classification
     * @return
     */
    @PostMapping("/addOne")
    public ResultDTO addOne(@RequestBody Classification classification) {
        return classificationService.addOneClassification(classification);
    }

    /**
     * 更新分类
     *
     * @param classification
     * @return
     */
    @PostMapping("/updateOne")
    public ResultDTO updateOne(@RequestBody Classification classification) {
        return classificationService.updateOneClassification(classification);
    }


    /**
     * 删除该分类以及其所有子分类
     *
     * @param id
     * @return
     */
    @GetMapping("/deleteOne/{id}")
    public ResultDTO<Integer> deleteOne(@PathVariable("id") Long id) {
        return classificationService.deleteOneClassification(id);
    }


}
